<!-- 表格明细数据提取 -->
<template>
  <el-dialog fullscreen :append-to-body="true" title="明细数据提取" :visible.sync="show" :close-on-click-modal="false"
             custom-class="nopadding">
    <div>
      <button class="btn btn-sm btn-primary" @click="exportXls()">导出到Excel</button>
      <button class="btn btn-sm btn-danger" @click="show=false">关闭</button>
    </div>
    <el-table :data="tableData" :height="height" border style="width: 100%" header-row-class-name="tableHeadbg">
      <template v-for="(item, index) in cols">
        <el-table-column :key="item.name" align="center" :prop="'c'+index" :label="item.name"></el-table-column>
      </template>
    </el-table>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 20, 50, 100]"
      :current-page="page"
      :page-size="rows"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </el-dialog>
</template>

<script>
import request from "@/utils/request"
import $ from 'jquery'

export default {
  data() {
    return {
      show: false,
      cols: [],
      tableData: [],
      height: 500,
      total: null,
      rows: 20,
      page: 1,
      header: [],
      comp: null,
      pms: null
    }
  },
  mounted() {
    this.height = $(window).height() - 150;
  },
  computed: {},
  methods: {
    linkDetail(comp, pms) {
      pms = eval("({" + pms + "})");
      this.pms = pms;
      this.comp = comp;
      let ts = this;
      this.show = true;
      request({
        method: "POST",
        url: "/bi/bireport/header",
        params: {dsetId: comp.dsetId, dsid: comp.dsid},
      }).then(resp => {
        ts.cols = resp.rows;
        ts.loadDatas(comp, pms);
      });
    },
    loadDatas() {
      let ts = this;
      let comp = this.comp;
      let pms = this.pms;
      var json = {pms: pms, dsetId: comp.dsetId, dsid: comp.dsid, page: ts.page, rows: ts.rows};
      request({
        headers: {'Content-Type': 'application/json'},
        method: "POST",
        url: "/bi/bireport/detail",
        data: json,
      }).then(resp => {
        ts.tableData = resp.rows;
        ts.total = resp.total;
      });
    },
    handleSizeChange(v) {
      this.rows = v;
      this.loadDatas();
    },
    handleCurrentChange(v) {
      this.page = v;
      this.loadDatas();
    },
    exportXls() {
      location.href = '/bi/bireport/exportDetail';
    }
  },
  watch: {}
}
</script>

<style lang="less" scoped>

</style>
